package com.abel.web.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.abel.web.view.ForgotPasswordViewBean;

public class ForgotPasswordValidator implements Validator {

	@Override
	public boolean supports(Class clazz) {

		return ForgotPasswordViewBean.class.equals(clazz);
	}

	@Override
	public void validate(Object obj, Errors errors) {

		ForgotPasswordViewBean viewBean = (ForgotPasswordViewBean)obj;
		
		if (viewBean.getEmail() == null
				|| viewBean.getEmail().equals("")) {
			
			errors.rejectValue("email", "error.null",null,"Email address is a required field");
		}

		if (viewBean.getUserName() == null
				|| viewBean.getUserName().equals("")) {
			
			errors.rejectValue("userName", "error.null",null,"User Name is a required field");
		}

	}


}
